package com.leyou.evaluate.controller;

import com.leyou.evaluate.service.MangoService;
import com.leyou.order.pojo.OrderEvaluate;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class MangoController {

    @Autowired
    private MangoService mangoService;
    //1.添加评论到mangoDB数据库
    @PostMapping("/save")
    public ResponseEntity<Void> saveEvaluate(@RequestBody OrderEvaluate orderEvaluate){
        mangoService.saveEvaluate(orderEvaluate);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    //2.根据spuId查看所有的商品评价
    @GetMapping("/findAll")
    public ResponseEntity<List<OrderEvaluate>> findAll(
            @RequestParam("spuId") Long spuId,
            @RequestParam(value = "pitch",required = false) Integer pitch){
        List<OrderEvaluate> orderEvaluates= mangoService.findAll(spuId,pitch);
        return ResponseEntity.ok(orderEvaluates);
    }
}
